﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Agile_E
{
    public partial class ManagerSearch : System.Web.UI.Page
    {
        protected string fname;
        protected string lname;
        private string EmpID;
        private string workphone;
        private string cellphone;
        private string sqlquery;
        private int counter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!User.IsInRole("Manager"))
            {
                HLaddEmp.Visible = false;
                HLaddEmp.Enabled = false;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            fname = txtfname.Text;
            lname = txtlname.Text;
            EmpID = txtEmpID.Text;
            workphone = txtWphone.Text;
            cellphone = txtCPhone.Text;
            counter = 0;
            sqlquery = "Select * From Employees";

            if (fname != string.Empty)
            {
                counter++;
                if (counter > 1)
                    sqlquery += " and First_Name like '%" + fname + "%'";
                else
                    sqlquery += " where First_Name like '%" + fname + "%'";
            }
            if (lname != string.Empty)
            {
                counter++;
                if (counter > 1)
                    sqlquery += " and Last_name like  '%" + lname + "%'";
                else
                    sqlquery += " where Last_name like '%" + lname + "%'";
            }

            if (EmpID != string.Empty)
            {
                counter++;
                if (counter > 1)
                    sqlquery += " and Employee_ID like '%" + EmpID + "%'";
                else
                    sqlquery += " where Employee_ID like '%" + EmpID + "%'";
            }

            if (workphone != string.Empty)
            {
                counter++;
                if (counter > 1)
                    sqlquery += " and Home_Phone like '%" + workphone + "%'";
                else
                    sqlquery += " where Home_Phone like '%" + workphone + "%'";
            }

            if (cellphone != string.Empty)
            {
                counter++;
                if (counter > 1)
                    sqlquery += " and Cell_Phone like '%" + cellphone + "%'";
                else
                    sqlquery += " where Cell_Phone like '%" + cellphone + "%'";
            }
            try
            {
                srcEmployee.SelectCommand = sqlquery;
                ((Main)((SearchMP)this.Master).Master).clearStatus();
                srcEmployee.DataBind();
            }
            catch (Exception ex)
            {
                ((Main)((SearchMP)this.Master).Master).writeStatus(ex.Message, true);
            }
        }
     /*   protected void grdDealers_OnRowCreated(Object sender, GridViewRowEventArgs e)
        {
            if (!User.IsInRole("Manager"))
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Cells[6].CssClass = "hiddencol";
                }
                else if (e.Row.RowType == DataControlRowType.Header)
                {
                    e.Row.Cells[6].CssClass = "hiddencol";
                }
            }
        }*/
    }
}
